﻿using AnyCAD.Foundation;
using AnyCAD.NX.ViewModel;
using Rapid.Sketch.Plugin.Model;
using System.ComponentModel;

namespace Rapid.Sketch.Plugin.SectionBar
{
    public class SectionBarViewModel : ComponentViewModel
    {
        SectionBarModel Model { get => (SectionBarModel)_Model; }
        public SectionBarViewModel(ShapeElement instance, PropertyComponent properties, Document doc, PropertyChangedEventHandler callback)
            : base(new SectionBarModel(), instance, properties, doc)
        {
            Model.Load(properties);

            PropertyChanged += callback;
        }

        public double InnerRadius
        {
            get => GetProperty(nameof(InnerRadius), Model.InnerRadius);
            set => SetProperty(nameof(InnerRadius), ref Model.InnerRadius, value, () => { return value > 0; }, nameof(OutterRadius));
        }
        public double Thickness
        {
            get => GetProperty(nameof(Thickness), Model.Thickness);
            set => SetProperty(nameof(Thickness), ref Model.InnerRadius, value, () => { return value > 0; }, nameof(OutterRadius));
        }

        public double OutterRadius
        {
            get => InnerRadius + Thickness;
        }
        public double Length
        {
            get => GetProperty(nameof(Length), Model.Length);
            set => SetProperty(nameof(Length), ref Model.InnerRadius, value, () => { return value > 0; });
        }
    }
}
